<template>
    <div class="refund">
        <header>退款管理</header>
        <div class="contents">
            <div class="conditions">
                <div class="condition_1">
                    <div class="keywords">
                        <span>
                            <label style="visibility:hidden;">我</label>订单号：</span>
                        <el-input v-model.trim="input1" placeholder="请输入" style="width:400px;"></el-input>
                    </div>
                    <div class="status">
                        <span>退款状态：</span>
                        <el-select v-model="value1" clearable placeholder="请选择" style="width:300px;">
                            <el-option v-for="item in options1" :key="item.value" :label="item.label" :value="item.value"> </el-option>
                        </el-select>
                    </div>                    
                    <el-button type="danger" style="background:#e7251a;margin-left:40px;" @click.native="querys">查询</el-button>
                    <el-button @click.native="resets">重置</el-button>
                    <el-button @click.native="exports">导出</el-button>
                </div>
                <div class="condition_2">
                    <div class="market_type">
                        <span>选择时间：</span>
                        <el-date-picker v-model="value2" type="datetimerange" :picker-options="pickerOptions1" range-separator="~" start-placeholder="开始日期" end-placeholder="结束日期" align="right"> </el-date-picker>
                    </div>
                    <div class="shops">
                        <span>咖啡店：</span>
                        <el-select :disabled="disA" clearable v-model="value4" placeholder="请选择" style="width:300px;">
                            <el-option v-for="item in options4" :key="item.COMP_ID" :label="item.SHOP_NAME" :value="item.COMP_ID"> </el-option>
                        </el-select>
                    </div>
                </div>
            </div>
            <div class="tables">
                <el-table v-loading="loading" :data="listData" style="width: 100%">
                    <el-table-column type="index" label="排序" width="50"> </el-table-column>
                    <el-table-column prop="ORDER_NO" label="订单号" width="150"> </el-table-column>
                    <el-table-column prop="PHONE" label="手机号" width="150"> </el-table-column>
                    <el-table-column prop="TRADE_TIME" label="下单时间" width="200">
                        <template slot-scope="scope">
                            <span v-if="scope.row.TRADE_TIME">{{ scope.row.TRADE_TIME | filterTimess }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="AMOUNT" label="退款金额" width="100"> </el-table-column>
                    <el-table-column prop="TRADENO" label="交易流水号" width="220"> </el-table-column>
                    <el-table-column prop="REFUND_STATUS" label="状态" width="100">
                        <template slot-scope="scope">
                            <span v-if="scope.row.REFUND_STATUS===0">待退款</span>
                            <span v-if="scope.row.REFUND_STATUS===1">已退款</span>
                            <span v-if="scope.row.REFUND_STATUS===2">已关闭</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="MASTER_NAME" label="操作人" width="100"> </el-table-column>
                    <el-table-column prop="LAST_UPDATE_TIME" label="操作时间" width="250">
                        <template slot-scope="scope">
                            <span v-if="scope.row.LAST_UPDATE_TIME">{{ scope.row.LAST_UPDATE_TIME | filterTimess }}</span>
                            <span v-else>--</span>
                        </template>
                    </el-table-column>
                    <el-table-column prop="options" label="操作" width="50">
                        <template slot-scope="scope">
                            <span class="edits" @click="goDetail(scope.row.REFUND_ID)">详情</span>
                        </template>
                    </el-table-column>
                </el-table>
                <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="page1" :page-sizes="[6, 8, 10]" :page-size="pageSize1" layout="total, sizes, prev, pager, next, jumper" :total="tableDatas.COUNT"> </el-pagination>
            </div>
        </div>
        <!-- 导出 要用表单 -->
        <footer>
            <form method="post" name="forms" style="opacity:0;">
                <input type="text" name="jsonParams" id="jsons" value="" />
                <input type="submit" value="提交" /> </form>
        </footer>
    </div>
</template>
<script>
    import dateSelect from '@/assets/js/date_time_picker.js' //日期选择器数据封装
    import { asyncRouterMap } from '@/router/index'
    import { setCookie, getCookie } from '@/assets/js/cookie'
    export default {
        name: 'refund',
        data() {
            return {
                value1: '', //退款状态
                value2: '', //选择时间   对应操作时间             
                input1: '', //订单号    
                pickerOptions1: dateSelect,
                showMenuList: false,
                options1: [{
                    value: 0,
                    label: '待退款'
                }, {
                    value: 1,
                    label: '已退款'
                }, {
                    value: 2,
                    label: '已关闭'
                }],
                tableDatas: [],
                loading: true,
                page1: 1, //当前页数
                pageSize1: 6, //每页多少条
                value4:'',//门店
                options4:[],
                arr_one: [],
                arr_two: [],
                str_one: '', //一级菜单字符串
                str_two: '', //二级菜单字符串
                disA: false, //下拉框是否禁用
            }
        },
        computed: {
            //请求参数
            objs() {
                let obj = {};
                obj.PAGE_NO = this.page1;
                obj.PAGE_SIZE = this.pageSize1;
                this.input1 ? obj.ORDER_NO = this.input1 : null;
                if(this.value1 === 0 || this.value1) {
                    obj.REFUND_STATUS = this.value1;
                }
                if(this.value2 === null){
                	this.value2 = '';
                }
                if(this.value2.length > 0) {
                    obj.STATR_TIME = this.value2[0].getTime();
                    obj.END_TIME = this.value2[1].getTime();
                } 
                if(this.value4 && this.value4 !== 'QB'){
                	obj.COMP_ID = this.value4;
                }
                return obj;
            },            
            //分页数据
            listData() {                
                if(this.tableDatas.REFUND_LIST) {
                    return this.tableDatas.REFUND_LIST;
                }
            },
        },
        created() {
        	/* ----------权限管理---------- */
            if(getCookie('compId') !== 0) {
            	this.disA = true;
                let self = this;
                //console.log(asyncRouterMap);
                this.$axiosPost('/4SCAFE/cafeUser/getMenuListByUserId.action', {
                    CAFEUSER_ID: getCookie('userId')
                }).then(res => {
                    //console.log(res);
                    if(res.STATUS_CODE === 1) {
                        //动态加载路由
                        res.MENU_DATA.forEach((v) => {
                            //一级菜单
                            self.arr_one.push(v.MENUID);
                            //二级菜单
                            v.MENUS.forEach((n) => {
                                self.arr_two.push(n.SECMENUNAME);
                            })
                        })
                    }
                    self.str_one = self.arr_one.join(',');
                    self.str_two = self.arr_two.join(',');
                    //0-功能  11-管理  19-统计  20-设置  
                    //asyncRouterMap[0].hidden = true;  
                    //asyncRouterMap[0].children[0].hidden = true;
                    //--------------------------功能----------------------------
                    if(self.str_one.indexOf(2) === -1) {
                        this.$set(asyncRouterMap[0], 'hidden', true);
                    }
                    if(self.arr_two.indexOf('营销管理') === -1) {
                        this.$set(asyncRouterMap[0].children[0], 'hidden', true);
                    }
                    if(self.arr_two.indexOf('优惠券管理') !== -1) {                    	
                        this.$set(asyncRouterMap[0].children[1], 'hidden', false);
                    }
                    if(self.arr_two.indexOf('广告位管理') === -1) {
                        this.$set(asyncRouterMap[0].children[2], 'hidden', true);
                    }
                    if(self.arr_two.indexOf('积分商城管理') === -1) {
                        this.$set(asyncRouterMap[0].children[3], 'hidden', true);
                    }
                    //--------------------------功能----------------------------
                    //--------------------------管理----------------------------
                    if(self.str_one.indexOf(3) === -1) {
                        this.$set(asyncRouterMap[11], 'hidden', true);
                    }
                    if(self.str_two.indexOf('门店管理') === -1) {
                        this.$set(asyncRouterMap[11].children[0], 'hidden', true);
                    }
                    if(self.str_two.indexOf('商品管理') === -1) {
                        this.$set(asyncRouterMap[11].children[1], 'hidden', true);
                    }
                    if(self.str_two.indexOf('会员管理') === -1) {
                        this.$set(asyncRouterMap[11].children[2], 'hidden', true);
                    }
                    if(self.str_two.indexOf('订单管理') === -1) {
                        this.$set(asyncRouterMap[11].children[3], 'hidden', true);
                    }
                    if(self.str_two.indexOf('退款管理') === -1) {
                        this.$set(asyncRouterMap[11].children[4], 'hidden', true);
                    }
                    //--------------------------管理----------------------------
                    //--------------------------统计----------------------------
                    if(self.str_one.indexOf(4) === -1) {
                        this.$set(asyncRouterMap[19], 'hidden', true);
                    }
                    if(self.str_two.indexOf('用户分析') === -1) {
                        this.$set(asyncRouterMap[19].children[0], 'hidden', true);
                    }
                    if(self.str_two.indexOf('订单分析') === -1) {
                        this.$set(asyncRouterMap[19].children[1], 'hidden', true);
                    }
                    if(self.str_two.indexOf('储存卡分析') === -1) {
                        this.$set(asyncRouterMap[19].children[2], 'hidden', true);
                    }
                    //--------------------------统计----------------------------
                    //--------------------------设置----------------------------
                    if(self.str_one.indexOf(5) === -1) {
                        this.$set(asyncRouterMap[20], 'hidden', true);
                    }
                    if(self.str_two.indexOf('积分设置') === -1) {
                        this.$set(asyncRouterMap[20].children[0], 'hidden', true);
                    }
                    if(self.str_two.indexOf('账号设置') === -1) {
                        this.$set(asyncRouterMap[20].children[1], 'hidden', true);
                    }
                    if(self.str_two.indexOf('系统设置') === -1) {
                        this.$set(asyncRouterMap[20].children[2], 'hidden', true);
                    }
                    //--------------------------设置----------------------------
                    console.log(self.str_one, self.str_two);
                })
            }
            /* ----------权限管理---------- */
        	this.get4SCafeShopList();        	
        },
        methods: {
        	//获取所有门店
            get4SCafeShopList() {
                this.$axiosPost('/4SCAFE/CafeActivitySystem/get4SCafeShopList.action').then(res => {
                    if(res.STATUS_CODE === 1) {
                        this.options4 = res.SHOP_LIST;
                        //门店列表增加 全部 二字
                        this.options4.unshift({
                        	COMP_ID:'QB',
                        	SHOP_NAME:'全部'
                        });
                        if(getCookie('compId')) {
                            this.value4 = getCookie('compId')
                        } else {
                            this.value4 = res.SHOP_LIST[0].COMP_ID;
                        }
                        this.getList();
                    }
                })
            },
        	//退款列表
        	getList(){
        		this.loading = true;
                this.$axiosPost('/4SCAFE/userRefundAuditSystem/getCafeUserRefundAuditList.action', this.objs).then(res => {
                    //console.log(res);
                    if(res.STATUS_CODE === 1) {
                        this.loading = false;
                        this.tableDatas = res;
                    }
                })
        	},
            //退款详情
            goDetail(id) {
                this.$router.push({
                    path: '/manages/refundDetail/' + id
                });
            },
            handleSizeChange(val) {
                this.loading = true;
                this.pageSize1 = val;
                this.getList();
            },
            handleCurrentChange(val) {
                this.loading = true;
                this.page1 = val;
                this.getList();
            },
            //查询
            querys() {
                this.getList();
            },
            //重置
            resets() {
                this.input1 = this.value1 = this.value2 = '';
            },
            //导出
            exports() {
                this.loading = true;
                let that = this;
                this.listData.forEach(function(i) {
                    that.$set(i, 'TRADE_TIME', that.formats(i.TRADE_TIME));
                    that.$set(i, 'LAST_UPDATE_TIME', that.formats(i.LAST_UPDATE_TIME));
                    that.$set(i, 'AMOUNT', '￥' + i.AMOUNT);
                    /* 状态start */
                    if(i.REFUND_STATUS === 0) {
                        that.$set(i, 'REFUND_STATUS', '待退款');
                    } else if(i.REFUND_STATUS === 1) {
                        that.$set(i, 'REFUND_STATUS', '已退款');
                    } else if(i.REFUND_STATUS === 2) {
                        that.$set(i, 'REFUND_STATUS', '已关闭');
                    }
                    /* 状态end */
                })
                //表单处理
                document.forms.setAttribute('action', window.getIps + '/4SCAFE/userRefundAuditSystem/exportCafeRefund.action');
                document.getElementById('jsons').value = JSON.stringify(this.listData);
                setTimeout(() => document.forms.submit(), 0);
                setTimeout(() => this.page1 = this.page1 + 1, 0);
                setTimeout(() => this.page1 = this.page1 - 1, 1000);
            },
            //时间格式化
            formats(val) {
                let y = new Date(val).getFullYear();
                let m = new Date(val).getMonth() + 1 >= 10 ? new Date(val).getMonth() + 1 : '0' + (new Date(val).getMonth() + 1);
                let d = new Date(val).getDate() >= 10 ? new Date(val).getDate() : '0' + new Date(val).getDate();
                let h = new Date(val).getHours() >= 10 ? new Date(val).getHours() : '0' + new Date(val).getHours();
                let ms = new Date(val).getMinutes() >= 10 ? new Date(val).getMinutes() : '0' + new Date(val).getMinutes();
                let s = new Date(val).getSeconds() >= 10 ? new Date(val).getSeconds() : '0' + new Date(val).getSeconds();
                return y + "-" + m + "-" + d + " " + h + ":" + ms + ":" + s;
            },
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
    .refund {
        header {
            background: #fff;
            font-size: 22px;
            font-weight: 700;
            padding: 20px;
        }
        .contents {
            width: 97%;
            margin: 25px auto;
            padding: 15px 25px;
            background: #fff;
            .conditions {
                span {
                    white-space: nowrap;
                }
                .condition_1 {
                    display: flex;
                    .keywords {
                        display: flex;
                        align-items: center;
                        .el-input {
                            margin-left: 5px;
                            margin-right: 10px;
                        }
                    }
                    .status {
                        margin: 0 15px;
                    }
                }
                .condition_2 {
                    margin: 20px 0;
                    display:flex;
                    .shops{
                    	margin-left:43px;
                    }
                }
            }
            .tables {
                border-top: 1px solid #eee;
                .edits {
                    color: #1d93ff;
                    cursor: pointer;
                    &:hover {
                        text-decoration: underline;
                    }
                }
                .el-pagination {
                    text-align: center;
                    margin-top: 30px;
                    background: #fff;
                }
            }
        }
    }
</style>